package com.yanqu.road.server.pb;

import com.yanqu.road.entity.sacrifice.UserSacrifice;
import com.yanqu.road.entity.sacrifice.UserSacrificePatronsData;
import com.yanqu.road.pb.sacrifice.SacrificeProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.config.SacrificeConfigMgr;

import java.util.List;

public class SacrificePb {
    public static SacrificeProto.SacrificeDataMsg.Builder parseSacrificeDataMsg(UserSacrifice userSacrifice){
        if(null == userSacrifice){
            return null;
        }
        SacrificeProto.SacrificeDataMsg.Builder msg = SacrificeProto.SacrificeDataMsg.newBuilder();
        msg.setDamage(userSacrifice.getTodayDamage().toString());
        return msg;
    }

    public static SacrificeProto.SacrificePatronsDataTempMsg.Builder parseSacrificePatronsDataTempMsg(GamePlayer player, UserSacrificePatronsData userSacrificePatronsData){
        if(null == userSacrificePatronsData){
            return null;
        }
        SacrificeProto.SacrificePatronsDataTempMsg.Builder msg = SacrificeProto.SacrificePatronsDataTempMsg.newBuilder();
        msg.setPatronsId(userSacrificePatronsData.getPatronsId());
        int canBattleTimes = SacrificeConfigMgr.getPatronsMaxSacrificeAttackTimes(player, userSacrificePatronsData.getPatronsId()) - userSacrificePatronsData.getBattleTimes();
        if(canBattleTimes < 0){
            canBattleTimes = 0;
        }
        msg.setCanAttackTimes(canBattleTimes);
        return msg;
    }

    public static SacrificeProto.SacrificePatronsDataListMsg.Builder parseSacrificePatronsDataListMsg(GamePlayer player, List<UserSacrificePatronsData> userSacrificePatronsDataList){
        SacrificeProto.SacrificePatronsDataListMsg.Builder listMsg = SacrificeProto.SacrificePatronsDataListMsg.newBuilder();
        if(null != userSacrificePatronsDataList){
            for(UserSacrificePatronsData userSacrificePatronsData : userSacrificePatronsDataList){
                SacrificeProto.SacrificePatronsDataTempMsg.Builder msg = parseSacrificePatronsDataTempMsg(player, userSacrificePatronsData);
                if(null != msg){
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }

    public static SacrificeProto.SacrificeKillBossUserInfoMsg.Builder parseSacrificeKillBossUserInfoMsg(String nickName, String decoration){
        SacrificeProto.SacrificeKillBossUserInfoMsg.Builder msg = SacrificeProto.SacrificeKillBossUserInfoMsg.newBuilder();
        msg.setKillBossNickName("");
        msg.setDecoration("");
        if(null != nickName) {
            msg.setKillBossNickName(nickName);
        }
        if(null != decoration) {
            msg.setDecoration(decoration);
        }
        return msg;
    }
}